<?php

use think\migration\Migrator;

class ChatMessageUserCancel extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    protected string $name = 'chat_message';

    public function change(): void
    {
        //增加一个字段
        $table = $this->table($this->name);
        if (!$table->hasColumn('user_cancel')) {
            $table->addColumn('user_cancel', 'tinyinteger', [
                'limit'   => 1,
                'default' => 0,
                'comment' => '用户取消',
                'after'   => 'carry_num'
            ])->save();
        }
    }
}
